<template>
  <view class="report_container app_container_page">
    <view class="report_top"></view>
    <view class="childContent">
      <text class="childContentTitle">孩子信息</text>
      <view class="app_bgwith_wave">
        <view class="scroll-view_H">
          <view class="scroll-view-item_H" v-for="per of swiperList" :key="per.studentId">
            <view class="row"> 学校：{{ per.kindergartenName }} </view>
            <view class="row"> 班级：{{ per.className }} </view>
            <view class="row"> 姓名：{{ per.studentName }} </view>
            <template v-if="per.reportTime">
              <view class="row"> 上报时间：{{ per.reportTime }} </view>
              <view class="row"> 最近一次报告得分：{{ per.score }}分 </view>
            </template>
          </view>
          <view class="scroll_add" v-if="swiperList.length < 3" @click="handleJump('/pages/children/list')">
            <van-icon name="add" />
            <view>添加孩子信息</view>
          </view>
        </view>
      </view>
      <view class="childBtn">
        <view class="seeReport" @click="handleJump('/pages/children/list')"> 报告查看</view>
        <view class="contrastReport" @click="handleJump('/pagesSub/compare/list')">对比报告查看</view>
      </view>
    </view>
  </view>
</template>

<script>
import { getChildList } from '@/api/report'
export default {
  data() {
    return {
      swiperList: []
    }
  },
  computed: {
    isLogin() {
      return this.$store.getters.isLogin
    }
  },
  methods: {
    handleJump(url, needCheckLogin = true) {
      if (needCheckLogin && !this.$checkLogin()) return
      uni.navigateTo({
        url
      })
    },
    async fetchChildList() {
      try {
        const res = await getChildList()
        this.swiperList = res.data
      } catch (error) {
        console.log(error)
      }
    }
  },
  onShow() {
    if (this.isLogin) {
      this.fetchChildList()
    } else {
      this.swiperList = []
    }
  }
}
</script>

<style lang="scss">
.report_container {
  .report_top {
    width: 750rpx;
    height: 400rpx;

    background-image: url('#{$BASEURL}/report-1.png');
    background-repeat: no-repeat;
    background-size: 100% 100%;
  }

  .childContent {
    .childContentTitle {
      font-size: 40rpx;
      padding: 30rpx;
      display: block;
    }
    .scroll-view_H {
      display: flex;
      align-items: center;
      flex-flow: nowrap;
      overflow-x: auto;
      white-space: nowrap;
      padding: 30rpx 0 15rpx;
      .scroll-view-item_H {
        width: 300rpx;
        height: 210rpx;
        margin-left: 30rpx;
        background: #ffffc6;
        // box-shadow: 0px 10rpx 40rpx 0px rgba(0, 0, 0, 0.2);
        border-radius: 20rpx;
        display: inline-block;
        padding: 33rpx 16rpx;

        .row {
          font-size: 24rpx;
          font-weight: 500;
          color: #002a63;
          line-height: 30rpx;
          @include text-ellipsis();
        }
      }

      .scroll_add {
        display: flex;
        flex-flow: column;
        justify-content: center;
        flex: 0 0 auto;
        width: 300rpx;
        height: 210rpx;
        margin: 0 30rpx;
        padding: 0;
        color: #fff;
        background: unset;
        border-radius: 20rpx;
        border: 6rpx dashed #0059b5;
        text-align: center;
        .van-icon {
          font-size: 100rpx;
          margin-bottom: 18rpx;
        }
      }

      .noChildList {
        display: inline-block;
        width: 300rpx;
        height: 240rpx;
        border: 6rpx solid #0059b5;
        box-shadow: 0px 10rpx 40rpx 0px rgba(0, 0, 0, 0.2);
        background-color: red;
        display: flex;
        justify-content: center;
        align-items: center;
      }
    }

    .childBtn {
      margin: 0 30rpx;
      padding-bottom: 170rpx;
      display: flex;
      flex-direction: column;
      justify-content: space-between;

      view {
        width: 100%;
        height: 139rpx;
        padding-top: 63rpx;
        // box-shadow: 0px 20rpx 60rpx 0px rgba(0, 0, 0, 0.1);
        border-radius: 20rpx;
        background-repeat: no-repeat;
        background-size: cover;
        font-size: 40rpx;
        text-align: center;
      }

      .seeReport {
        background-image: url('#{$BASEURL}/report-3.png');
        margin-top: 50rpx;
        margin-bottom: 32rpx;
      }

      .contrastReport {
        padding-top: 54rpx;
        background-image: url('#{$BASEURL}/report-4.png');
      }
    }
  }
}
</style>
